//
//  MSAwardAndInviteVC.m
//  MSMain
//
//  Created by Dgh Hv on 2018/9/19.
//  Copyright © 2018年 土豆. All rights reserved.
//

#import "MSAwardAndInviteVC.h"
#import "MSAwardListVC.h"
#import "MSInviteListVC.h"
#import <VTMagic.h>
#import "MSInviteViewModel.h"

@interface MSAwardAndInviteVC ()<VTMagicViewDelegate,VTMagicViewDataSource>

@property (nonatomic, strong) VTMagicController *magicController;
@property (nonatomic, strong) NSArray           *menuArray;
@property (nonatomic, assign) NSUInteger         currentShowingPageId;

@end

@implementation MSAwardAndInviteVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isHidenNaviBar = YES;
    self.fd_prefersNavigationBarHidden = YES;
    [self setUI];
    // Do any additional setup after loading the view.
}

#pragma mark - set UI

-(void)setUI
{
    _magicController = [[VTMagicController alloc] init];
    //    _magicController.magicView.scro
    _magicController.view.translatesAutoresizingMaskIntoConstraints = NO;
    _magicController.magicView.navigationColor = RGB_HEX(0xffffff);
    _magicController.magicView.sliderColor = HEXCOLOR(0x000000);//滑动条
    _magicController.magicView.sliderHeight = 1;
    _magicController.magicView.itemSpacing = 27;
    _magicController.magicView.itemScale = 1;
    _magicController.magicView.displayCentered = YES;
    _magicController.magicView.switchStyle = VTSwitchStyleDefault;
    _magicController.magicView.layoutStyle = VTLayoutStyleCenter;
    if (IS_IPHONE_X) {
        _magicController.magicView.navigationHeight = 88.f;
    }else{
        _magicController.magicView.navigationHeight = 64.f;
    }
    _magicController.magicView.navigationInset = UIEdgeInsetsMake(20, 0, 0, 0);
    _magicController.magicView.againstStatusBar = NO;
    _magicController.magicView.sliderExtension = 2;
    _magicController.magicView.sliderOffset = 0;
    _magicController.magicView.dataSource = self;
    _magicController.magicView.delegate = self;
    _magicController.magicView.separatorColor = [UIColor groupTableViewBackgroundColor];
    [self addChildViewController:_magicController];
    [self.view addSubview:_magicController.view];
    [_magicController.magicView reloadData];
    [_magicController.magicView switchToPage:0 animated:NO];
    
    UIButton * backButton = [[UIButton alloc]init];
    [backButton setImage:IMAGE_NAMED(@"common_nav_btn_back_n-1") forState:UIControlStateNormal];
    backButton.frame = CGRectMake(5, 20, 40, 40);
    if (IS_IPHONE_X) {
        backButton.frame = CGRectMake(5, 50, 40, 40);
    }
    kWeakSelf(self);
    [backButton addTapBlock:^(UIButton *btn) {
        [weakself.navigationController popViewControllerAnimated:YES];
    }];
    [self.view addSubview:backButton];
}

#pragma mark - DataDelegate
- (NSArray<NSString *> *)menuTitlesForMagicView:(VTMagicView *)magicView {
    return self.menuArray;
}

- (UIButton *)magicView:(VTMagicView *)magicView menuItemAtIndex:(NSUInteger)itemIndex {
    static NSString *itemIdentifier = @"itemIdentifier";
    UIButton *menuItem = [magicView dequeueReusableItemWithIdentifier:itemIdentifier];
    if (!menuItem) {
        menuItem = [UIButton buttonWithType:UIButtonTypeCustom];
        [menuItem setTitleColor:HEXCOLOR(0x6A6978) forState:UIControlStateNormal];
        [menuItem setTitleColor:HEXCOLOR(0x000000) forState:UIControlStateSelected];
        menuItem.titleLabel.font = [UIFont systemFontOfSize:17.f];
    }
    return menuItem;
}
- (UIViewController *)magicView:(VTMagicView *)magicView viewControllerAtPage:(NSUInteger)pageIndex {
    NSString *title = self.menuArray[pageIndex];
    if ([title isEqualToString:@"奖励详情"]) {
        MSAwardListVC * awardVC = [[MSAwardListVC alloc]init];
        return awardVC;
    }else{
        MSInviteListVC * inviteVC = [[MSInviteListVC alloc]init];
        return inviteVC;
    }
}

- (void)magicView:(VTMagicView *)magicView viewDidAppear:(__kindof UIViewController *)viewController atPage:(NSUInteger)pageIndex {
    self.currentShowingPageId = pageIndex;
    NSLog(@"%zd", self.currentShowingPageId);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - getters & setters
-(NSArray *)menuArray
{
    if(_menuArray == nil)
    {
        _menuArray = @[@"奖励详情",@"邀请列表"];
    }
    return _menuArray;
}

@end
